package com.learn.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置类
 * 发布确认(高级)
 */
@Configuration
public class ConfirmConfig {

    public static final String CONFIRM_EXCHANGES_NAME = "confirm.exchange";
    public static final String CONFIRM_QUEUE_NAME = "confirm.queue";
    public static final String CONFIRM_ROUTING_KEY_NAME = "key1";


    //声明队列
    @Bean
    public Queue confirmQueue() {
        return QueueBuilder.durable(CONFIRM_QUEUE_NAME).build();
    }

    //延迟交换机
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange(CONFIRM_EXCHANGES_NAME);
    }


    @Bean
    public Binding delayedQueueBindingDelayedExchange(
            @Qualifier("confirmQueue") Queue confirmQueue,
            @Qualifier("directExchange") DirectExchange directExchange) {
        return BindingBuilder
                .bind(confirmQueue)
                .to(directExchange)
                .with(CONFIRM_ROUTING_KEY_NAME);
    }


}
